package com.hyt.it.ogt.download.base;

import com.hyt.model.QuotEditor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wuyingge
 * @version 1.0.0
 * @ClassName BaseController.java
 * @Description
 * @createTime 2022年03月29日 16:35:00
 */
@Slf4j
public abstract class BaseController {

    /**
     * @param binder ServletRequestDataBinder
     */
    @InitBinder
    public void initBinder(ServletRequestDataBinder binder) {
        /**
         * 自动转换日期类型的字段格式
         */
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
        //双引号特殊处理
        binder.registerCustomEditor(String.class, new QuotEditor());
        /**
         * 防止XSS攻击
         */
        //binder.registerCustomEditor(String.class, new StringEscapeEditor());
    }
}
